pub fn bczd_4_2() {
  // test1();
  // test2();
  test5();
}

fn test1() {
  static STATIC_VALUE: i32 = 0;
  static mut STATIC_MUT_VALUE: i32 = 9;
  const CONST_VALUE: i32 = 0;

  unsafe {
    STATIC_MUT_VALUE = 4;
  }
  println!("STATIC_VALUE={}", STATIC_VALUE);
  unsafe {
    println!("STATIC_MUT_VALUE={}", STATIC_MUT_VALUE);
  }
  println!("CONST_VALUE={}", CONST_VALUE);
}

// fn test2() {
//   static STATIC_VALUE: String = String::from("STATIC_VALUE");
//   static mut STATIC_MUT_VALUE: String = String::from("STATIC_MUT_VALUE");
//   const CONST_VALUE: String = String::from("CONST_VALUE");

//   unsafe {
//     STATIC_MUT_VALUE.push_str("string");
//   }
//   println!("STATIC_VALUE={}", STATIC_VALUE);
//   unsafe {
//     println!("STATIC_MUT_VALUE={}", STATIC_MUT_VALUE);
//   }
//   println!("CONST_VALUE={}", CONST_VALUE);
// }

// fn test3() {
//   static STATIC_VALUE:&str = "STATIC_VALUE";
//   static mut STATIC_MUT_VALUE: String = String::from("STATIC_MUT_VALUE");
//   const CONST_VALUE: String = String::from("CONST_VALUE");

//   unsafe {
//     STATIC_MUT_VALUE.push_str("string");
//   }
//   println!("STATIC_VALUE={}", STATIC_VALUE);
//   unsafe {
//     println!("STATIC_MUT_VALUE={}", STATIC_MUT_VALUE);
//   }
//   println!("CONST_VALUE={}", CONST_VALUE);
// }

fn test4() {
  let v1 = 2;
  let v2 = Box::new(5);
  let vv1 = v1;
  let vv2 = v2;

  println!("{}", v1);
  // println!("{}", v2); // 不是实现越多的特性越好，Box就不应该实现Copy特性
}

fn test5() {
  #[derive(Debug)]
  struct SubObject {
    value: i32,
  }
  impl Drop for SubObject {
    fn drop(&mut self) {
      println!("SubObject::{:?}", self.value);
    }
  }
  #[derive(Debug)]
  struct FatherObject {
    value: SubObject,
  }
  impl Drop for FatherObject {
    fn drop(&mut self) {
      println!("FatherObject::{:?}", self.value);
    }
  }

  let value = FatherObject {value: SubObject { value: 1 }};
  println!("{:?}", value);
}
